package org.kernely.stream.administration;

import org.kernely.ui.mvp.IKernelyView;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

/**
 * Show the administration of the streams.
 */
@SuppressWarnings("serial")
public class StreamAdministrationView extends VerticalLayout implements IKernelyView{
	
	/**
	 * The view ID, for the association between views and presenters
	 */
	public final static Class<? extends IKernelyView> ID_VIEW = StreamAdministrationView.class;
	
	private Button addButton;
	private Button editButton;
	private Button deleteButton;
	private Button lockButton;
	
	private HorizontalLayout buttonsLayout;
	
	private Table streamTable;
	
	/**
	 * Constructor of StreamAdministrationView
	 */
	public StreamAdministrationView(){
		this.addButton = new Button("Add a new stream");
		this.editButton = new Button("Edit a stream");
		this.deleteButton = new Button("Delete a stream");
		this.lockButton = new Button("Lock a stream");
		this.lockButton.setEnabled(false);
		this.deleteButton.setEnabled(false);
		this.editButton.setEnabled(false);
		
		this.buttonsLayout = new HorizontalLayout();
		
		this.buttonsLayout.addComponent(addButton);
		this.buttonsLayout.addComponent(editButton);
		this.buttonsLayout.addComponent(lockButton);
		this.buttonsLayout.addComponent(deleteButton);
		this.buttonsLayout.setSpacing(true);
		this.buttonsLayout.setMargin(true);
		
		this.streamTable = new Table();
		this.streamTable.setSizeFull();
		this.streamTable.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		
		this.streamTable.addContainerProperty("Title", String.class, null);
		this.streamTable.addContainerProperty("Messages", Integer.class,  null);
		this.streamTable.addContainerProperty("Subscriptions", Integer.class,  null);
		this.streamTable.addContainerProperty("Redactors", Integer.class,  null);
		this.streamTable.addContainerProperty("Locked", String.class, null);
		this.streamTable.setSelectable(true);
		this.streamTable.setImmediate(true);
		this.streamTable.setPageLength(20);
		
		this.streamTable.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY);
		this.streamTable.setSortContainerPropertyId("Title");
		this.streamTable.setSortAscending(true);
		
		this.addComponent(this.buttonsLayout);
		this.addComponent(this.streamTable);
		this.setSizeFull();
	}

	/**
	 * Unused method
	 */
	public final Component getComponent() {
		return this;
	}


	/**
	 * @return the addButton
	 */
	public final Button getAddButton() {
		return addButton;
	}

	/**
	 * @param addButton the addButton to set
	 */
	public final void setAddButton(Button addButton) {
		this.addButton = addButton;
	}

	/**
	 * @return the editButton
	 */
	public final Button getEditButton() {
		return editButton;
	}

	/**
	 * @param editButton the editButton to set
	 */
	public final void setEditButton(Button editButton) {
		this.editButton = editButton;
	}

	/**
	 * @return the deleteButton
	 */
	public final Button getDeleteButton() {
		return deleteButton;
	}

	/**
	 * @param deleteButton the deleteButton to set
	 */
	public final void setDeleteButton(Button deleteButton) {
		this.deleteButton = deleteButton;
	}

	/**
	 * @return the lockButton
	 */
	public final Button getLockButton() {
		return lockButton;
	}

	/**
	 * @param lockButton the lockButton to set
	 */
	public final void setLockButton(Button lockButton) {
		this.lockButton = lockButton;
	}

	/**
	 * @return the streamTable
	 */
	public final Table getStreamTable() {
		return streamTable;
	}

	/**
	 * @param streamTable the streamTable to set
	 */
	public final void setStreamTable(Table streamTable) {
		this.streamTable = streamTable;
	}
	
	

}
